import * as actionTypes from '../constants/index';
import {filterTabData} from '../until'

const moduleList = (state = null, action) => {
  switch (action.type) {
    case actionTypes.GET_MODULES:
      return [...action.data];
    case actionTypes.SHOW_HOME:
      return state.map((item)=>{
        if(item.id===action.id){
          item.home = action.home
        }
        return item
      });

    // case actionTypes.ADD_COLUMN_LIST:
    //   return [...state, action.data];
    // case actionTypes.REMOVE_COLUMN_LIST:
    //   return state.filter((item) => item !==state.splice(action.data, 1)[0])
    default:
      return state;
  }
};

const initState = {
  tableData: [],
  switchlist: [],
  isFirst: true,
  sortType: 'desc',
  scope: -1,
  websiteType: -1,
  positiveOrNegative: -1,
  currentPage: 1,
  limit: 10,
  sortField: 'poTime',
  abroad: -1,
  categoryId: '',
  searchType: "all",
  topicId: "",
  totals: 0,
  choselist: [0, 0, 0, 0, 0, 0, 0],
  id: '',
  titleContentPrint: '',
  loading: true,
  updatewebsite: '',
  updomain: '',
  uptype: 0 //0 加入 1 修改


}
const moduleInforesult = (state = initState, action) => {
  switch (action.type) {
    case actionTypes.MODULE_GET_TAG_LIST:
      return {...state, tableData: action.payload, totals: action.total}
    case actionTypes.MODULE_PAGESIZE:
      return {...state, limit: action.pagesize}
    case actionTypes.MODULE_DELETE:
      return {...state, tableData: filterTabData(state.tableData, action.id)}
    case actionTypes.MODULE_EXPORTSELECTS:
      return {...state, id: action.id}
    case actionTypes.MODULE_REMOVEACTION:
      return {...state, choselist: action.choselist}
    case actionTypes.MODULE_DETAIL:
      return {...state, id: action.id, titleContentPrint: action.titleContentPrint}
    case actionTypes.MODULE_LOADING:
      return {...state, loading: action.loading}
    case actionTypes.MODULE_UPDATE:
      return {...state, updatewebsite: action.updatewebsite, updomain: action.updomain, uptype: action.uptype}
    default:
      return state;
  }
}
export {moduleInforesult, moduleList}
